package com.twu.biblioteca;

import java.util.Comparator;

//for Comparison by Release Year
class MovieComparatorReleaseYear implements Comparator<Movie>
{
    public int compare(Movie movie1, Movie movie2) {
        int difference=movie1.releaseYear-movie2.releaseYear;
        if(difference>0)
            return 1;
        else if(difference<0)
            return -1;
        else
            return 0;
    }
}

//for Comparison by Movie Name
class MovieComparatorMovieName implements Comparator<Movie>
{
    public int compare(Movie movie1, Movie movie2) {
        return movie1.movieName.compareToIgnoreCase(movie2.movieName);
    }
}

//for Comparison by Director Name
class MovieComparatorDirectorName implements Comparator<Movie>
{
    public int compare(Movie movie1, Movie movie2) {
        return movie1.directorName.compareToIgnoreCase(movie2.directorName);
    }
}

//for Comparison by Movie Rating
class MovieComparatorMovieRating implements Comparator<Movie>
{
    public int compare(Movie movie1, Movie movie2) {
        int difference=movie1.rating-movie2.rating;
        if(difference>0)
            return 1;
        else if(difference<0)
            return -1;
        else
            return 0;
    }
}

public class Movie {
    String movieName;
    String directorName;
    int releaseYear;
    int rating;

    public Movie()
    {
        movieName="";
        directorName="";
        releaseYear=0;
        rating=-1;
    }
    public Movie(String movieName,String directorName,int releaseYear,int rating)
    {
        this.movieName=movieName;
        this.directorName=directorName;
        this.releaseYear=releaseYear;
        // movies are rated in the scale of 0-10 and if movie is not pre-rated then rating value is negative
        if(rating>10)
            this.rating=10;
        else
            this.rating=rating;
    }
    public Movie(String movieName,String directorName,int releaseYear)
    {
        this.movieName=movieName;
        this.directorName=directorName;
        this.releaseYear=releaseYear;
        // movies are rated in the scale of 0-10 and if movie is not pre-rated then rating value is negative
        this.rating=-1;
    }
    public String displayMovieRating()
    {
        String displayStringForMovieRating="";
        if(rating<0)
            displayStringForMovieRating="N/A";
        else
        {
            int loopCounter;
            for(loopCounter=0;loopCounter<rating;loopCounter++)
                displayStringForMovieRating+="*";
        }
        return displayStringForMovieRating;
    }
}
